package cn.udrm.water.base.v1.manager.restful;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.udrm.water.base.v1.commons.models.ResponseParam;
import cn.udrm.water.base.v1.manager.dto.BaseRoleDto;
import cn.udrm.water.base.v1.manager.service.BaseRoleService;

@RestController
@RequestMapping(value="v1/restful/role")
public class BaseRoleRestful {
	@Autowired
	private BaseRoleService roleService;
	
	@GetMapping(value="getAll")
	public ResponseParam<List<BaseRoleDto>> getAll() {
		List<BaseRoleDto> all = roleService.getAll();
		return new ResponseParam<List<BaseRoleDto>>("数据获取成功", 200, all);
	}
	
	@GetMapping(value="getWithAllById/{id}")
	public ResponseParam<BaseRoleDto> getWithAllById(@PathVariable(value="id") String id) {
		BaseRoleDto withAllById = roleService.getWithAllById(id);
		return new ResponseParam<BaseRoleDto>("数据获取成功", 200, withAllById);
	}
	
	@GetMapping(value="getRolesByOrgId")
	public ResponseParam<List<BaseRoleDto>> getRolesByOrgId(@RequestParam(value="orgId") String orgId) {
		List<BaseRoleDto> findByOrganizationId = roleService.findByOrganizationId(orgId);
		return new ResponseParam<List<BaseRoleDto>>("数据获取成功", 200, findByOrganizationId);
	}
	
	@PostMapping(value="save")
	public ResponseParam<BaseRoleDto> save(@RequestBody BaseRoleDto roleDto) {
		BaseRoleDto save = roleService.save(roleDto);
		return new ResponseParam<BaseRoleDto>("数据保存成功", 200, save);
	}
	
	@PostMapping(value="update")
	public ResponseParam<BaseRoleDto> update(@RequestBody BaseRoleDto roleDto) {
		BaseRoleDto update = roleService.update(roleDto);
		return new ResponseParam<BaseRoleDto>("数据保存成功", 200, update);
	}
	
	@GetMapping(value="getSelfById/{id}")
	public ResponseParam<BaseRoleDto> getSelfById(@PathVariable(value="id") String id) {
		BaseRoleDto baseRoleDto = roleService.get(id);
		return new ResponseParam<BaseRoleDto>("数据获取成功", 200, baseRoleDto);
	}

}
